import 'package:flutter/material.dart';
import 'package:verse_systems/commom/global/global.dart';
import 'package:verse_systems/commom/global/jpush_service.dart';
import 'package:verse_systems/commom/routers/navigator_utils.dart';
import 'package:verse_systems/commom/routers/routes_pages_name.dart';
import 'package:verse_systems/mz_app.dart';
import 'package:verse_systems/net/src/sparrow_dio_config.dart';
import 'package:verse_systems/utils/account_util.dart';

void main() async {
  await Global.init();
  await JPUSHService.registerJPush();
  await AccountUtil.clearBaseUrl();
  NavigatorUtils.handleAppVersion(success: (bool value) {
    if (value) {
      realRunApp();
    }
  });
}

void realRunApp() async {
  bool? isLogin = await AccountUtil.getLoginStatus();
  final String languageTag = await AccountUtil.getAppLanguages();
  SparrowDioConfig.setLanguage("zh_${languageTag.toLowerCase()}");
  
  if (isLogin) {
    SparrowDioConfig.setToken(await AccountUtil.getUserToken());
    runApp(MzApp(initPage: RoutesPage.Application, language: languageTag));
  } else {
    runApp(MzApp(initPage: RoutesPage.Login, language: languageTag));
  }
}
